import os
import random
import math
import pygame
from pygame.locals import *

import Globals

class LightSnowBall (pygame.sprite.Sprite):
	"""A simple snowball"""
	def __init__(self, pos, dest):
		pygame.sprite.Sprite.__init__(self) # Initialize base class			
		File = os.path.join('data', "snowball.png")
		self.image = pygame.image.load(File).convert_alpha()
		self.rect = self.image.get_rect()
		self.rect.center = pos
		self.dest = dest
		self.temperature = -5 # this is object is cool
		self.isPassed = False

	def update(self):
		#fra nuvrende position mod dest
		dx = self.dest[0] - self.rect.center[0]
		dy = self.dest[1] - self.rect.center[1]
		d = math.sqrt(pow(dx,2)+pow(dy,2))
		if d > 4:
			x = math.floor((4 / d) * dx)
			y = math.floor((4 / d) * dy)
			self.rect.move_ip(x,y)
		elif self.isPassed == False:
			dx = math.floor(dx * 2)
			dy = math.floor(dy * 2)
			self.dest = dx + self.rect.center[0], dy + self.rect.center[1]
			self.isPassed = True
		else:
			self.kill()

	def hit(self, target):
		target.hit(self)
		self.kill()

